package a1_3;

import java.util.ArrayList;
import java.util.List;

/**
 * 学生类，关联学院和课程
 */
public class Student {
    private String studentId;
    private String studentName;

    // 关联：属于1个学院
    private School school;

    // 关联：参加1~5门课程（List存储，控制数量）
    private List<Subject> enrolledSubjects = new ArrayList<>();

    public Student() {}

    public Student(String studentId, String studentName, School school) {
        this.studentId = studentId;
        this.studentName = studentName;
        this.school = school;
    }

    // 添加课程（1~5门）
    public boolean addEnrolledSubject(Subject subject) {
        if (enrolledSubjects.size() < 5) {
            return enrolledSubjects.add(subject);
        }
        throw new IllegalStateException("学生最多参加5门课程");
    }

    // 移除课程（至少1门）
    public boolean removeEnrolledSubject(Subject subject) {
        if (enrolledSubjects.size() > 1) {
            return enrolledSubjects.remove(subject);
        }
        throw new IllegalStateException("学生至少参加1门课程");
    }

    // Getter/Setter
    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public School getSchool() {
        return school;
    }

    public void setSchool(School school) {
        this.school = school;
    }

    public List<Subject> getEnrolledSubjects() {
        return new ArrayList<>(enrolledSubjects);
    }
}